package custom.base.http;

import android.content.Context;

import custom.base.utils.TxtUtil;
import custom.base.utils.store.PreferencesManager;


/**
 * Created by cubebox on 2017/7/24.
 */

public class TokenManager {
    private static TokenManager instance = null;
    private PreferencesManager preferencesManager = null;
    private String token = "";

    public TokenManager(Context context) {
        preferencesManager = PreferencesManager.getInstance(context);
    }

    public static TokenManager getInstance(Context context) {
        synchronized (TokenManager.class) {
            if (instance == null)
                instance = new TokenManager(context);
        }
        return instance;
    }

    /**
     * 得到token
     */
    public String getToken() {
        if (TxtUtil.isEmpty(this.token)) {
            token = preferencesManager.getString(preferencesManager.PRE_TOKEN, "");
        }
        return token;
    }

    /**
     * 保存token
     */
    public void saveToken(String token) {
        this.token = token;
        preferencesManager.putString(preferencesManager.PRE_TOKEN, token);
    }

    /**
     * 清除
     */
    public void clearToken() {
        this.token = "";
        preferencesManager.putString(preferencesManager.PRE_TOKEN, "");
    }

}
